<template>
  <div>
     <el-card class="box-card">
      <div slot="header" class="clearfix">
      <span>品牌管理列表</span>
      <el-button style="float: right; padding: 3px 0" type="button"   @click="goAddBrand">添加</el-button>
      
      </div>
     </el-card>

    <el-table :data="brandList" border style="width: 100%">
       <el-table-column prop="id" label="编号"> </el-table-column>
        <el-table-column prop="name" label="品牌名称"></el-table-column>
        <el-table-column prop="first_letter" label="品牌首字母"></el-table-column>
       
       
       <el-table-column prop="sort" label="排序"></el-table-column>
       <el-table-column label="品牌制造商" align="center">
        <template slot-scope="scope">
          <el-switch
            v-model="scope.row.show_status"
            :active-value="1"
            :inactive-value="0"
          >
          </el-switch>
        </template>
      </el-table-column>

      <el-table-column label="是否显示" align="center">
        <template slot-scope="scope">
          <el-switch
            v-model="scope.row.show_status"
            :active-value="1"
            :inactive-value="0"
          >
          </el-switch>
        </template>
      </el-table-column>
      <el-table-column label="价格/货号">
        <template slot-scope="scope">
          <div>价格：{{scope.row.product_count}}</div>
          <div>货号：{{1000}}</div>
        </template>
      </el-table-column>

        <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button size="small" @click="editFun(scope.row.id)"
            >编辑</el-button
          >
          <el-button type="danger" size="small" @click="delFun(scope.row.id)"
            >删除</el-button
          >
        </template>
      </el-table-column>
     </el-table>
  </div>
</template>

<script>
import {fetchBrandList,deleteProduct} from "@/api/product"
export default {
    name:'brand',
    data:function(){
      return {
        brandList:[]
      }
    },
    mounted () {
      this.getBrandList()
    },
    methods: {
       delFun(id){
      console.log('删除触发了',id);
       this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          deleteProduct({ id: id }).then((res) => {
            console.log(res);
            if (res.type == "success") {
              this.$message({
                type: "success",
                message: "删除成功!",
              });
              this.getBrandList()
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
      async getBrandList(){
        const res=await fetchBrandList()
        console.log(res);
        this.brandList=res.data
      },
      goAddBrand(){
        this.$router.push('/pms/addBrand')
      },
      editFun(id,val){
          console.log('修改触发了',id);
          this.$router.push("/pms/productbrandupdate/" + id+'/'+val);
      },
    }
}
</script>

<style>

</style>